<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://mars3d.cn " />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico" />
    <title>三维地图 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <!--第三方lib-->
    <script
      type="text/javascript"
      src="../lib/include-lib.js"
      libpath="../lib/"
      include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d"
    ></script>

    <link href="css/style.css" rel="stylesheet" />
  </head>

  <body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="mars3dContainer" class="mars3d-container"></div>

    <!-- 面板 -->
    <div class="infoview">
      <input id="btnSelPoint" type="button" class="btn btn-primary" value="追踪目标点" />

      <!-- <button id="btnGetRegion" class="btn btn-primary">获取区域边界值</button>
      <button id="btnGetCenter" class="btn btn-primary">获取中心点坐标</button>
      <button id="btnRemoveAll" class="btn btn-primary">清除</button> -->
    </div>

    <!-- 图层管理相关处理js -->
    <script type="text/javascript" src="./js/graphicManager.js"></script>

    <script src="./js/common.js"></script>
    <script type="text/javascript">
      'use script' //开发环境建议开启严格模式

      var map

      function initMap(options) {
        //合并属性参数，可覆盖config.json中的对应配置
        var mapOptions = mars3d.Util.merge(options, {
          scene: {
            center: { lat: 30.808451, lng: 116.295952, alt: 15993, heading: 2, pitch: -29 },
          },
        })

        //创建三维地球场景
        map = new mars3d.Map('mars3dContainer', mapOptions)

        //创建矢量数据图层
        var graphicLayer = new mars3d.layer.GraphicLayer()
        map.addLayer(graphicLayer)

        //图层管理的相关处理，代码在\js\graphicManager.js
        initLayerManager(graphicLayer)

        //加一些演示数据
        addGraphic_01(graphicLayer)
        addGraphic_02(graphicLayer)
        addGraphic_03(graphicLayer)
      }

      function addGraphic_01(graphicLayer) {
        let position = [116.359147, 30.990366, 6000]

        //加个飞机
        var graphicFJ = new mars3d.graphic.ModelPrimitive({
          position: position,
          style: {
            url: '//data.mars3d.cn/gltf/mars/feiji.glb',
            scale: 1,
            minimumPixelSize: 50,
            heading: 150,
          },
        })
        graphicLayer.addGraphic(graphicFJ)

        //四凌锥追踪体
        var graphicFrustum = new mars3d.graphic.FrustumPrimitive({
          position: position,
          targetPosition: [116.317411, 30.972581, 1439.7], //可选
          style: {
            angle: 10,
            // length: 4000, //targetPosition存在时无需传
            color: '#02ff00',
            opacity: 0.4,
            outline: true,
            outlineColor: '#ffffff',
            outlineOpacity: 1.0,
          },
          asynchronous: false,
        })
        graphicLayer.addGraphic(graphicFrustum)

        $('#btnSelPoint').click(function () {
          map.graphicLayer.startDraw({
            type: 'point',
            style: {
              pixelSize: 8,
              color: '#ffff00',
            },
            success: function (graphic) {
              var position = graphic.positionShow
              map.graphicLayer.clear()

              graphicFrustum.targetPosition = position
            },
          })
        })

        $('#btnGetRegion').click(function () {
          var coords = graphicFrustum.getRayEarthPositions()

          //显示边界点
          map.graphicLayer.clear()
          coords.forEach(function (item) {
            var primitive = new mars3d.graphic.PointPrimitive({
              position: item,
              style: {
                color: '#ff0000',
                pixelSize: 8,
                outline: true,
                outlineColor: '#ffffff',
                outlineWidth: 2,
                clampToGround: true,
              },
            })
            map.graphicLayer.addGraphic(primitive)
          })
        })

        $('#btnGetCenter').click(function () {
          map.graphicLayer.clear()

          var groundPosition = graphicFrustum.groundPosition
          if (!groundPosition) {
            haoutil.alert('当前与地球无交点')
            return
          }

          var primitive = new mars3d.graphic.PointPrimitive({
            position: groundPosition,
            style: {
              color: '#ff0000',
              pixelSize: 8,
              outline: true,
              outlineColor: '#ffffff',
              outlineWidth: 2,
              clampToGround: true,
            },
          })
          map.graphicLayer.addGraphic(primitive)
        })

        $('#btnRemoveAll').click(function () {
          map.graphicLayer.clear()
        })
      }

      function addGraphic_02(graphicLayer) {
        var graphic = new mars3d.graphic.FrustumPrimitive({
          position: [116.25813, 30.983059, 5000],
          style: {
            angle: 7,
            length: 4000,
            color: '#FF0000',
            opacity: 0.4,
            outline: true,
            outlineColor: '#ffffff',
            outlineOpacity: 1.0,
          },
          asynchronous: false,
        })
        graphicLayer.addGraphic(graphic)
      }

      function addGraphic_03(graphicLayer) {
        //加个卫星
        var graphicFJ = new mars3d.graphic.ModelPrimitive({
          position: [116.303349, 31.070789, 7000],
          style: {
            url: '//data.mars3d.cn/gltf/mars/weixin.gltf',
            scale: 1,
            minimumPixelSize: 50,
            heading: 70,
          },
        })
        graphicLayer.addGraphic(graphicFJ)

        var graphic = new mars3d.graphic.FrustumPrimitive({
          position: [116.303349, 31.070789, 7000],
          style: {
            angle: 10,
            angle2: 0.01,
            length: 7000,
            heading: 70,
            color: '#00ffff',
            opacity: 0.7,
          },
          asynchronous: false,
        })
        graphicLayer.addGraphic(graphic)
      }
    </script>
  </body>
</html>
